import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:niu_app/configs/app_style_config.dart';
import 'package:niu_app/pages/model/homepage/news_model.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niu_app/views/jk/jk_text.dart';
class newswidget extends StatelessWidget {

  final newsmodel dataModel;

  const newswidget({Key key, this.dataModel}) : super(key: key);



  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w,vertical: 12.h),
      decoration: BoxDecoration(
        color: AppStyleConfig.TextColor,
        border: Border(
          bottom: BorderSide(width: 0.5,color: AppStyleConfig.color5.withOpacity(0.6))
        )
      ),
      child:Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Container(
                    height: 26.w,
                    width: 26.w,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(
                        Radius.circular(75)
                      ),
                      color: dataModel.state==0?AppStyleConfig.background:AppStyleConfig.color2,
                    ),
                    child: Icon(
                      Icons.notifications,
                      size: 20.w,
                      color:AppStyleConfig.TextColor,
                    ),
                  ),
                  JKText(
                    data: "【${dataModel.title??""}】",
                    color: Colors.black,
                    fontSize: 12.w,
                    weight: FontWeight.bold,
                  ),
                  buildState(state: dataModel.state),
                ],
              ),
              JKText(
                data: dataModel.time??"",
                color: AppStyleConfig.color2,
                fontSize: 12.w,
              ),
            ],
          ),
          SizedBox(height: 12.w,),
          Row(
            children: [
              Visibility(
                visible: dataModel.state==0,
                  child: Container(
                    margin: EdgeInsets.only(right: 8.w),
                    width: 8.w,
                    height: 8.w,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: AppStyleConfig.color8
                    ),
                  )
              ),
              Expanded(
                  child: JKText(
                    data: dataModel.title1??"",
                    color: dataModel.state==0?Colors.black:AppStyleConfig.color2,
                    fontSize: 12.w,
                    weight: FontWeight.bold,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
              )
            ],
          )
        ],
      ),
    );
  }
  Widget buildState({int state}){
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 4.w,vertical: 0.h),
      decoration: BoxDecoration(
        border: Border.all(
          width: 0.5,color: state==0?Colors.blue:Colors.grey
        ),
        borderRadius: BorderRadius.all(
          Radius.circular(2.w)
        )
      ),
      child: JKText(
        data: state==0?"未读":"已读",
        color: state==0?Colors.blue:Colors.grey,
        fontSize: 10.w,
      ),
    );
  }
}
